package com.fortune.cat.bean;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author zhaozeyang
 * @date 2019/4/22 20:19
 * @description
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DegradeConfig {

    @ApiModelProperty("对应RouteDefinitionRecipient.qualifiedName")
    private String routeId;

    private List<DegradeInfo> degradeInfoList;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DegradeInfo {
        @ApiModelProperty("1:仅根据path匹配 2：根据path和query参数降级 3：根据path和header参数降级")
        private Integer degradeType;

        /**
         * 路径
         */
        private String path;

        /**
         * 方法
         */

        private String method;


        @ApiModelProperty("仅当degradeType为1时，才会用到此属性")
        private ReturnInfo commonReturnInfo;


        @ApiModelProperty("仅当degradeType为2时，才会用到此属性")
        private List<QueryInfo> queryInfo;

        @ApiModelProperty("仅当degradeType为3时，才会用到此属性")
        private List<HeaderInfo> headerInfo;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class ReturnInfo {
        /**
         * http状态吗
         */
        private Integer httpStatus;

        /**
         * 返回数据
         */
        private String commonReturnJson;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class QueryInfo {

        private String queryName;

        private String queryValue;

        private ReturnInfo returnInfo;


    }


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class HeaderInfo {

        private String HeaderName;

        private String HeaderValue;

        private ReturnInfo returnInfo;

    }

}
